package vn.appsmobi.activity;

import vn.appsmobi.ulti.Constant;
import vn.appsmobi.ulti.Log;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

public class JoinActivity extends Activity
{
  private void handleIntent()
  {
	    Intent intent = getIntent();
	    Uri uri = intent.getData();
	    String action = intent.getAction();
	    if ("android.intent.action.SEARCH".equals(action))
	    {
	      String str2 = intent.getStringExtra("query");
	      if (!TextUtils.isEmpty(str2))
	        startSearchActivity(str2, "global");
	    }
	    else if(Intent.ACTION_VIEW.equals(action))
	    {
	    	// get packagename from id uri
	    	String packagename = uri.getQueryParameter("id");
	    	String auto			= uri.getQueryParameter("auto");
	    	Log.v("auto  String:" + auto);
	    	Log.v("Constant.INTENT_EXTRA_APP_PAKAGENAME:" + packagename);
	    	intent = new Intent(this, DetailActivity.class);	
	    	intent.putExtra(Constant.INTENT_EXTRA_APP_PAKAGENAME, packagename);
	    	if(auto!= null && auto.equals(Constant.INTENT_EXTRA_NOTIFICATION_AUTO))
	    	{
	    		intent.putExtra(Constant.INTENT_EXTRA_APP_AUTO_INSTALL, true);
	    		
	    	}
	        startActivity(intent);
	    }
	    else
	    {
	    	intent  = new Intent(this,MainTabActivity.class);
	    	startActivity(intent);
	    }
    }
  

  private void startSearchActivity(String paramString1, String paramString2)
  {
    Intent intent = new Intent(this, SearchActivity.class);
    intent.putExtra("searchString", paramString1);

    startActivity(intent);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    handleIntent();
    finish();
  }
}
